package com.taijihuabao.modules.controller;

import com.taijihuabao.common.jsonresult.JsonResult;
import com.taijihuabao.common.commonutils.PageResult;
import com.taijihuabao.modules.model.basedto.IdDTO;
import com.taijihuabao.modules.model.checkin.dto.*;
import com.taijihuabao.modules.model.checkin.vo.CheckInListVO;
import com.taijihuabao.modules.service.CheckInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;

/**
 * 考勤管理
 *
 * @author changhui.tu
 */
@Api(tags = "考勤管理")
@RestController
@RequestMapping("/api/v1/check")
public class CheckInController {

    @Autowired
    private CheckInService checkService;

    /**
     * 获取考勤列表
     *
     * @param listDTO
     * @return
     */
    @ApiOperation("考勤列表")
    @GetMapping
    public JsonResult selCheckInList(CheckInListDTO listDTO) {
        PageResult pageResult = checkService.selCheckInList(listDTO);
        return JsonResult.success(pageResult);
    }

    /**
     * 获取考勤信息
     *
     * @param idDTO
     * @return
     */
    @ApiOperation("考勤列表")
    @GetMapping("/info")
    public JsonResult selCheckInInfo(IdDTO idDTO) {
        CheckInListVO checkInInfo = checkService.selCheckInInfo(idDTO);
        return JsonResult.success(checkInInfo);
    }

    /**
     * 打卡初始化
     *
     * @param checkInitDTO
     * @return
     */
    @ApiOperation("初始打卡")
    @PostMapping("/initCheck")
    public JsonResult initClock(@RequestBody CheckInitDTO checkInitDTO) throws ParseException {
        return JsonResult.success(checkService.initCheck(checkInitDTO));
    }

    @ApiOperation("补卡日期校验")
    @PostMapping("/timeVerify")
    public JsonResult checkInTimeVerify(@RequestBody CheckInTimeVerifyDTO checkInTimeVerifyDTO) {
        return JsonResult.success(checkService.checkInTimeVerify(checkInTimeVerifyDTO));
    }

    /**
     * 考勤打卡
     *
     * @param check
     * @return
     * @throws ParseException
     */
    @ApiOperation("考勤打卡")
    @PostMapping
    public JsonResult attendanceClock(@RequestBody CheckInCrFromDTO check) throws ParseException {
        checkService.attendanceClock(check);
        return JsonResult.success();
    }

    /**
     * 报表导出
     *
     * @param response
     */
    @ApiOperation("报表导出")
    @GetMapping("/export")
    public void export(HttpServletResponse response, CheckInExportDTO checkInExportDTO) throws IOException {
        checkService.checkInExport(response, checkInExportDTO);
    }

    /**
     * 按月导出
     *
     * @param response
     */
    @ApiOperation("按月导出")
    @GetMapping("/export/month")
    public void exportForMonth(HttpServletResponse response) throws IOException {
        checkService.exportForMonth(response);
    }

    /**
     * 按周导出
     *
     * @param response
     */
    @ApiOperation("按周导出")
    @GetMapping("/export/week")
    public void exportForWeek(HttpServletResponse response) throws IOException {
        checkService.exportForWeek(response);
    }

}
